import java.util.Scanner;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2022-10-24
 * Time:20:44
 */
class Tree{
    char val;
    Tree left;
    Tree right;
    public Tree(char val) {
        this.val = val;
    }
}
public class NewTreeNode {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String a = in.nextLine();
            Tree root = createTree(a);
            inOrder(root);
        }
//        Stack<Tree> stack=new Stack<>();
//        stack.add(null);

    }
    public static void inOrder(Tree root) {
        if (root == null) {
            return;
        }
        inOrder(root.left);
        System.out.print(root.val + " ");
        inOrder(root.right);
    }
    public static int i = 0;
    public static Tree createTree(String str) {
        Tree root = null;
        if (str.charAt(i) != '#') {
            root = new Tree(str.charAt(i));
            i++;
            root.left = createTree(str);
            root.right = createTree(str);
        } else {
            i++;
        }
        return root;
    }
}
